<template>
	<view class="content">
		<navbar :appname="title" :icon="iconshow" v-show="flag"></navbar>
		<view class="container" v-show="flag">
			<scroll-view scroll-y="true">
				<view class="search" @tap="handleToSearch">
					<text class="iconfont icon-fangdajing"></text>
					<input type='text' :placeholder="tips"/>
				</view>
				<view class="music-charts-list">
					<view class="music-charts-item" v-for="(item, index) in topList" :key="index" @tap="handleToList(item.id)">
						<view class="music-charts-image">
							<image :src="item.coverImgUrl"></image>
							<text>{{item.updateFrequency}}</text>
						</view>
						<view class="music-charts-names">
							<view v-for="(ditem,dindex) in item.tracks" :key="dindex">{{dindex + 1}}.{{ditem.first}} - {{ditem.second}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import '@/common/iconfont.css';
	import navbar from '@/components/navbar/navbar.vue';
	import {topData} from '../../common/api.js'
	export default {
		components:{
			navbar
		},
		data() {
			return {
				title:"海豚音乐",
				iconshow:false,
				tips:'搜索歌曲',
				topList:[],
				flag:false,
			}
		},
		onLoad() {
			uni.showLoading({
				title: '请稍等，加载中……',
				mask: false
			});
			
			topData()
			.then((res)=>{
				// console.log(res)
				if (res.length){
					this.topList = res
				}
				this.flag = true
				uni.hideLoading()
			})
			.catch((reason)=>{
				// console.log(reason)
				this.flag = true
				uni.hideLoading()
			});
		},
		methods: {
			handleToList(listId){
				uni.navigateTo({
					url: '../mlist/mlist?listId=' + listId,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			handleToSearch(){
				uni.navigateTo({
					url: '../search/search',
					// success: res => {},
					// fail: () => {},
					// complete: () => {}
				});
			},
		}
	}
</script>

<style scoped>
	.content{
		
	}
	.search{
		display: flex;
		align-items: center;
		height: 70rpx;
		margin: 70rpx 30rpx 30rpx 30rpx;
		background: #f7f7f7;
		border-radius: 50rpx;
	}
	
	.search input{
		font-size: 28rpx;
		flex: 1;
	}
	
	.search text{
		font-size: 26rpx;
		margin-right: 26rpx;
		margin-left: 28rpx;
	}
	
	.music-charts-list{
		margin: 0 30rpx;
	}
	
	.music-charts-item{
		display: flex;
		margin-bottom: 34rpx;
	}
	
	.music-charts-image{
		position: relative;
		width: 212rpx;
		height: 212rpx;
		border-radius: 5rpx;
		overflow: hidden;
		margin-right: 22rpx;
	}
	.music-charts-image image{
		width: 100%;
		height: 100%;
	}
	
	.music-charts-image text{
		position: absolute;
		left: 12rpx;
		bottom: 16rpx;
		font-size: 20rpx;
		color: white;
	}
	
	.music-charts-names{
		display: flex;
		flex-direction: column;
		font-size: 22rpx;
		line-height: 66rpx;
	}
	
	.music-charts-names view{
		width: calc(100vw - 294rpx); /*限制宽度*/
		white-space:nowrap;/*一行显示*/
		overflow: hidden;/*超出隐藏*/
		text-overflow: ellipsis;/*超出省略*/
	}
	
</style>
